package com.jinlejia.feedback.common;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import java.util.Map;

/**
 *
 */

public class FbDataFilter {


    public static int code(Map<String, Object> map){
        int code = 0;
        String codeStr = String.valueOf(map.get("code"));
        try{
            code = Integer.parseInt(codeStr);
        }catch (Exception ignored){
        }
        return code;
    }

    public static String message(Map<String, Object> map){
        String message = String.valueOf(map.get("message"));
        if (TextUtils.isEmpty(message) || "null".equalsIgnoreCase(message)){
            return "未知错误";
        }
        return message;
    }

    public static boolean filter(Map<String, Object> map){
        if (code(map)==200){
            return true;
        }
        return false;
    }

    public static Map<String,Object> data(Map<String,Object> map){
        String data = String.valueOf(map.get("data"));
        Map<String,Object> map1 = (Map<String,Object>) JSON.parse(data);
        return map1;
    }

    public static JSONArray dataArray(Map<String,Object> map){
        String data = String.valueOf(map.get("data"));
        return JSON.parseArray(data);
    }

}
